﻿using Lcygcc.Domain.Repository.DB;
using Lcygcc.Domain.Repository.Entity;
using Lcygcc.Domain.Service;
using Lcygcc.Infrastructure.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lcygcc.Domain.ServiceImpl
{
    /// <summary>
    /// 类名称：PersonService.cs
    /// 作者：gcb
    /// 创始时间：2019-05-23
    /// 简要描述：1.获取Oracle中人事资料插入到JieLink中
    /// </summary>
    public class PersonService : IPersonService
    {
        //private readonly 
        private readonly PersonRepository m_PersonRepository = null;

        private readonly IRepository<ControlPerson> m_ControlPerson = null;

        public PersonService(PersonRepository personRepository,IRepository<ControlPerson> controlPerson)
        {
            m_PersonRepository = personRepository;
            m_ControlPerson = controlPerson;
        }
        /// <summary>
        /// 通过Oracle获取人事资料集合
        /// </summary>
        public void GetPersonsByOracle()
        {
            List<OraclePerson> list = m_PersonRepository.GetPersonsByOracle();
            if (list.Count > 0)
            {
                foreach (var person in list)
                {
                    var personDb = m_ControlPerson.db.Queryable<ControlPerson>().Where(x => x.PersonNo == person.PersonNo).FirstOrDefault();
                    if (personDb == null)
                    {
                        personDb = new ControlPerson();
                        personDb.PersonNo = person.PersonNo;
                        personDb.PGUID = Guid.NewGuid().ToString();
                        personDb.Mobile = person.Phone;
                        personDb.PersonId = "123456";
                        //personDb.PersonNo = "00001132";
                        personDb.PersonName = person.Name;


                        m_ControlPerson.Insert(personDb);
                    }
                    else
                    {

                    }
                }
            }
        }
    }
}
